// BT4_Array.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "Array.h"
#include "SinhVien.h"
#include "Comparable.h"
#include<iostream>
#include <sstream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	
	Array<SinhVien> svArray;
	stringstream out;
	// fill array
	for(int i = 0; i < svArray.getSize() - 1; i++)
	{
		out << i;
		svArray[i].setMSSV(out.str());
		svArray[i].setName(out.str());
		svArray[i].setDiemTrungBinh(svArray.getSize() - i);
	}

	svArray[9].setMSSV(out.str());
	svArray[9].setName(out.str());
	svArray[9].setDiemTrungBinh(svArray.getSize() );

	// print arry before sort
	cout << "Before sort:\n";
	for(int i = 0; i < svArray.getSize() ; i++)
	{
		 cout << "svArray[" << i << "]:\t";
		 cout << "mssv:" <<svArray[i].getMSSV() <<", ten" << svArray[i].getName() << ", diemTrungBinh:" << svArray[i].getDiemTrungBinh()  <<"\n";
	}

	//sort
	Comparable<SinhVien>* cp = new AndComparable<SinhVien>();
	cp->addComparable(new AdvanceCompareable<SinhVien,string>(DESCEND, &SinhVien::getMSSV));
	cp->addComparable(new AdvanceCompareable<SinhVien,double>(DESCEND, &SinhVien::getDiemTrungBinh));

	svArray.sort(InsertionSort<SinhVien>::getSortObject(), cp);
																																// Singleton destroy
	InsertionSort<SinhVien>::releaseSortObject();
	// print arry after sort
	cout << "\nAfter sort:\n";
	for(int i = 0; i < svArray.getSize(); i++)
	{
		 cout << "svArray[" << i << "]:\t";
		 cout << "mssv:" <<svArray[i].getMSSV() <<", ten" << svArray[i].getName() << ", diemTrungBinh:" << svArray[i].getDiemTrungBinh()  <<"\n";
	}
	
	return 0;
}

